package com.itheima.controller;

import com.itheima.pojo.Category;
import com.itheima.pojo.FrontMenus;
import com.itheima.pojo.Result;
import com.itheima.service.FrontMenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menus")
public class FrontMenusController {
    @Autowired
    private FrontMenusService frontMenusService;
    @PostMapping
    public Result add(@RequestBody @Validated(FrontMenus.Add.class) FrontMenus frontMenus){
        frontMenusService.add(frontMenus);
        return Result.success();
    }
    @GetMapping
    public Result<List<FrontMenus>> list(){
        List<FrontMenus> fs = frontMenusService.list();
        return Result.success(fs);
    }
    @PutMapping
    public Result update(@RequestBody @Validated(FrontMenus.Update.class) FrontMenus frontMenus){
        frontMenusService.update(frontMenus);
        return Result.success();
    }
    @DeleteMapping
    public Result<FrontMenus> delete(FrontMenus frontMenus){
        frontMenusService.delete(frontMenus);
        return Result.success();
    }
}
